﻿/*-------------------------------------
//
//Copyright (C) 2007 开发二组 版权所有。
//
//文件名：Header.ascx.cs
//
//
//文件功能描述：起始页面的一些基本功能的实现
//
//
//创建标识：2007.11.27 何卫红
//修改标识：2007.11.27 殷悦
//创建描述：起始页面的一些基本功能的实现..
//
// 
//修改标识:2007.11.30 李正平
//修改描述:将所有的Response.Redirect()换成Server.Transfer();
//
//------------------------------------*/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using JXMSTC.SmartBusiness.BFL.IBLL;
using JXMSTC.SmartBusiness.BFL.BLLFactory;
 

public partial class Common_Controls_Header : System.Web.UI.UserControl
{
    //创建 产品类别的 webService 实例
    localhost.ProductService productType = new localhost.ProductService();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //将 类别名与ID绑定到DropDownList控件中
            BindCategory();

            

            //登录确定
            SureLogin();
        }
    }

    protected void BindCategory()
    {
       //异步调用
        
        productType.GetUpperCategoryListCompleted += new localhost.GetUpperCategoryListCompletedEventHandler(product_GetUpperCategoryListCompleted);
        productType.GetUpperCategoryListAsync();

    }

    
    /// <summary>
    /// 确定登陆
    /// </summary>
    protected void SureLogin()
    {
        if ((Session["CustomerID"] != null) && (Session["CustomerID"].ToString() != "CUS-00000000"))
        {
           //未登录
            Panel1.Visible = false;
            Panel3.Visible = false;
            Panel2.Visible = true;
            Panel4.Visible = true;
        }
        else
        {
            //已经登录
            Panel1.Visible = true;
            Panel3.Visible = true;
            Panel2.Visible = false;
            Panel4.Visible = false;
        }
    }

    void product_GetUpperCategoryListCompleted(object sender, localhost.GetUpperCategoryListCompletedEventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        try
        {
            //绑定到下拉列表中
            this.dropUpperCatory.DataSource =e.Result;
            //显示输出
            this.dropUpperCatory.DataTextField = "Name";
            this.dropUpperCatory.DataValueField = "UpperCategoryID";
            //绑定输出 
            this.dropUpperCatory.DataBind();

            ListItem li = new ListItem("全部商品", "");
            this.dropUpperCatory.Items.Insert(0, li);
        }
        catch (Exception e1)
        {
            Server.Transfer("~/Msg.aspx?msg=" + e1.Message);
        }
    }
    
    /// <summary>
    /// 注册
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnRegesiter_Click(object sender, ImageClickEventArgs e)
    {
        Server.Transfer("~/UserReg.aspx");
    }
    /// <summary>
    /// 顾客登录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnLogin_Click(object sender, ImageClickEventArgs e)
    {
          Server.Transfer("~/MemberCenter/UserLogin.aspx");

    }
    /// <summary>
    /// 顾客搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        string categoryID = this.dropUpperCatory.SelectedValue.Trim();
        int categoryIndex = this.dropUpperCatory.SelectedIndex;
        string strKey = this.txtSearchCondition.Text.Trim();
        strKey = strKey.Replace("'", "");
        strKey = strKey.Replace("--", "");
        Response.Redirect("~/Searcher.aspx?ProductName=" + strKey + "&categoryID=" + categoryID);//+"&index="+categoryIndex.ToString()

        this.dropUpperCatory.SelectedIndex = categoryIndex;
    }
    
    /// <summary>
    /// 退出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnExit_Click1(object sender, ImageClickEventArgs e)
    {
          //退出时清空Session,将Session中的值设置为默认的匿名用户
        Session.Clear();
        Server.Transfer("~/Default.aspx");

  
    }  
}
